package cn.toys.modular.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import lombok.Data;

@Data
public class CityArea implements Serializable {
    private Integer id;

    private Long areaCode;

    private String areaName;

    private String areaLevel;

    private Long parentAreaCode;

    private String parentAreaName;

    private String lon;

    private String lat;

    private Date createTime;

    private String statusCd;

    private static final long serialVersionUID = 1L;

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", areaCode=").append(areaCode);
        sb.append(", areaName=").append(areaName);
        sb.append(", areaLevel=").append(areaLevel);
        sb.append(", parentAreaCode=").append(parentAreaCode);
        sb.append(", parentAreaName=").append(parentAreaName);
        sb.append(", lon=").append(lon);
        sb.append(", lat=").append(lat);
        sb.append(", createTime=").append(createTime);
        sb.append(", statusCd=").append(statusCd);
        sb.append("]");
        return sb.toString();
    }

    public enum Column {
        id("id", "id", "INTEGER", false),
        areaCode("area_code", "areaCode", "BIGINT", false),
        areaName("area_name", "areaName", "VARCHAR", false),
        areaLevel("area_level", "areaLevel", "VARCHAR", false),
        parentAreaCode("parent_area_code", "parentAreaCode", "BIGINT", false),
        parentAreaName("parent_area_name", "parentAreaName", "VARCHAR", false),
        lon("lon", "lon", "VARCHAR", false),
        lat("lat", "lat", "VARCHAR", false),
        createTime("create_time", "createTime", "TIMESTAMP", false),
        statusCd("status_cd", "statusCd", "VARCHAR", false);

        private static final String BEGINNING_DELIMITER = "\"";

        private static final String ENDING_DELIMITER = "\"";

        private final String column;

        private final boolean isColumnNameDelimited;

        private final String javaProperty;

        private final String jdbcType;

        public String value() {
            return this.column;
        }

        public String getValue() {
            return this.column;
        }

        public String getJavaProperty() {
            return this.javaProperty;
        }

        public String getJdbcType() {
            return this.jdbcType;
        }

        Column(String column, String javaProperty, String jdbcType, boolean isColumnNameDelimited) {
            this.column = column;
            this.javaProperty = javaProperty;
            this.jdbcType = jdbcType;
            this.isColumnNameDelimited = isColumnNameDelimited;
        }

        public String desc() {
            return this.getEscapedColumnName() + " DESC";
        }

        public String asc() {
            return this.getEscapedColumnName() + " ASC";
        }

        public static Column[] excludes(Column ... excludes) {
            ArrayList<Column> columns = new ArrayList<>(Arrays.asList(Column.values()));
            if (excludes != null && excludes.length > 0) {
                columns.removeAll(new ArrayList<>(Arrays.asList(excludes)));
            }
            return columns.toArray(new Column[]{});
        }

        public static Column[] all() {
            return Column.values();
        }

        public String getEscapedColumnName() {
            if (this.isColumnNameDelimited) {
                return new StringBuilder().append(BEGINNING_DELIMITER).append(this.column).append(ENDING_DELIMITER).toString();
            } else {
                return this.column;
            }
        }

        public String getAliasedEscapedColumnName() {
            return this.getEscapedColumnName();
        }
    }
}